TARGET := main
TEXFILES := $(wildcard *.tex)
BIBFILES := $(wildcard *.bib)
FIGFILES := $(wildcard figure/*.jpg) $(wildcard figure/*.pdf)

# Programs and paths
# # This makefile assumes pdflatex and bibtex are in your path
# # 
BIBTEX   = bibtex
LATEX    = pdflatex
DVIPS    = dvips -tletter
PS2PDF   = ps2pdf
PS2EPS   = ps2eps
L2H      = latex2html -white -antialias -local_icons -long_titles 1 \
	                -show_section_numbers
POPTS    = --shell-escape

.PRECIOUS: %.dvi %.ps %.pdf %.aux

$(TARGET).pdf: $(TEXFILES) $(FIGFILES) $(BIBFILES) $(FIGFILES)
	-$(RM) -f *.aux
	-$(LATEX) $(TARGET).tex
	-$(BIBTEX) $(TARGET)
	-$(LATEX) $(TARGET).tex
	-$(LATEX) $(TARGET).tex
	@/bin/echo ""
	@/bin/echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@/bin/echo "               ++++ ANY UNDEFINED REFERENCES ++++"
	-@grep -i undef $(TARGET).log || echo "No undefined references."
	@/bin/echo "                 ++++ ANY EMPTY REFERENCES ++++"
	-@egrep -i -n -e 'cite{ *}' -e 'ref{ *}' $(TEXFILES) $(FIGFILES) || echo "No empty references."
	@/bin/echo "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
	@/bin/echo ""

wc:
	dvi2tty -w132 paper.dvi | wc

# Excluding references:
#       dvi2tty -w132 paper.dvi | awk 'R==0 {print;} /^References/ {R=1}' | wc


clean:       
	rm -f *.aux *.bbl *.dvi *.lof *.log *.pdf *.out *.toc *.lot *.blg

